package scanner.com.preference;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2016/6/22.
 */
public class MyPreference {
    private static final String PREF_FILE_NAME = "scanner";
    private static final String IS_SOUND_ON = "sound";
    private static final String IS_VIBRATE_ON = "vibrate";

    private static MyPreference self;

    public static synchronized MyPreference getInstance(Context context){
        if(self == null) self = new MyPreference(context);
        return self;
    }

    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    public MyPreference(Context context){
        sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME,Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public void setIsSoundOn(boolean on){
        editor.putBoolean(IS_SOUND_ON,on);
        editor.commit();
    }

    public void getIsSoundOn(boolean  defaultOn){
        sharedPreferences.getBoolean(IS_SOUND_ON,defaultOn);
    }
    public void setIsVibrateOn(boolean on){
        editor.putBoolean(IS_VIBRATE_ON,on);
        editor.commit();
    }

    public void getIsVibrateOn(boolean  defaultOn){
        sharedPreferences.getBoolean(IS_VIBRATE_ON,defaultOn);
    }
}


